package cn.doit.scala.day02.demo

import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.io.{BufferedSource, Source}

/**
 * @DATE 2021/12/25/14:43
 * @Author MDK
 * @Version 2021.2.2
 * */
object ScoreDemo {
  def main(args: Array[String]): Unit = {
    //获取文件内容
    val source: BufferedSource = Source.fromFile("data/stu.txt")
    //获取行数据
    val lines: Iterator[String] = source.getLines()
    //可变的数组集合
    val ab = ArrayBuffer[Student]()
    val ls = ListBuffer[Student]()

//    lines.foreach(println)
    while (lines.hasNext) {
      //处理每行数据  封装（到JavaBean类）
      val str: String = lines.next()
      //将每个数据添加到集合中
      val arr = str.split("\\s+")
      val stu: Student = Student(arr(0), arr(1), arr(2).toDouble)
      ls.append(stu)
    }
    println(ls)
    println(ab)
  }
}
